<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('model_job');
		$this->load->model('model_user');
	}

	public function index()
	{
		// echo $this->model_job->countAll();
		$this->load->library('pagination');
		$config['base_url'] = base_url()."trang-chu"; // xác định trang phân trang 
        $config['total_rows'] = $this->model_job->countAll(); // xác định tổng số record 
        $config['per_page'] = 10; // xác định số record ở mỗi trang 
        $config['use_page_numbers']  = TRUE;
        $config['next_link'] = 'Next »';
        $config['prev_link'] = '« Prev';
        $config['first_tag_open'] = $config['last_tag_open']= $config['next_tag_open']= $config['prev_tag_open'] = $config['num_tag_open'] = '<li>';
        $config['first_tag_close'] = $config['last_tag_close']= $config['next_tag_close']= $config['prev_tag_close'] = $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = "<li class='current'><a href=''>";
        $config['cur_tag_close'] = "</a></li>";
        $config['uri_segment'] = 2; // xác định segment chứa page number 
        $this->pagination->initialize($config);
        if($this->uri->segment(2) == ""){
        	$start = 0;
        }else{
        	$start = $this->uri->segment(2) * $config['per_page'] - $config['per_page'];
        }
		$data['home_job'] = $this->model_job->home_job($config['per_page'],$start);

		if($this->session->userdata('id')){
			$id = $this->session->userdata('id');
			if(($this->session->userdata('level')) && $this->session->userdata('level') == 2){
				$mssv = $this->model_user->get_student_name($id)['mssv'];
				if($this->model_user->test($mssv)){
					$test1 = explode("-", $this->model_user->test($mssv)['ki_nang']);
					$test2 = $test1[1];
					$data['job_hint'] = $this->model_user->job_hint($test2);
				}
			}
		}

		$data['mssv'] = $this->session->userdata('mssv');
		$data['title'] = "Trang Chủ";
		$data['subview'] = 'users/home';
		$this->load->view('main', $data);
	}

	public function search(){
		$key_search = $this->input->post('search');
		$type = $this->input->post('view-d');
		if($type == "cv"){
			if($key_search == ""){
				redirect(base_url()."trang-chu");
			}else{
				$data['info'] = $this->model_job->search_job($key_search);
				$data['title'] = "Kết quả tìm kiếm công việc";
				$data['subview'] = "users/search_job";
				$this->load->view('main', $data);
			}
		}elseif ($type == "hs") {
			if($key_search == ""){
				$data['info'] = $this->model_job->all_record();
				$data['title'] = "Kết quả tìm kiếm hồ sơ";
				$data['subview'] = "users/search_record";
				$this->load->view('main', $data);
			}else{
				$data['info'] = $this->model_job->search_record($key_search);
				$data['title'] = "Kết quả tìm kiếm hồ sơ";
				$data['subview'] = "users/search_record";
				$this->load->view('main', $data);
			}
		}
	}

	public function student_info($mssv){
		$data['student_info'] = $this->model_user->student_info($mssv);
		$data['title'] = "Thông tin sinh viên";
		$data['subview'] = "users/student_info_public";
		$this->load->view('main', $data);
	}

	public function introduce(){
		$data['title'] = "Giới thiệu tổng quan";
		$data['subview'] = "introduce";
		$this->load->view('main', $data);
	}

	public function hdt(){
		$data['title'] = "Hệ đào tạo";
		$data['subview'] = "hdt";
		$this->load->view('main', $data);
	}

	public function cctc(){
		$data['title'] = "Cơ cấu tổ chức";
		$data['subview'] = "cctc";
		$this->load->view('main', $data);
	}

	public function QA(){
		$data['title'] = "Hỏi đáp";
		$data['subview'] = "QA";
		$this->load->view('main', $data);
	}

}
